<!doctype html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="format-detection" content="telephone=no"/>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<meta name="format-detection" content="telephone=no">
	<title>央票通--立即注册</title>
	<style>
		*{
			margin:0;
			padding:0;
		}
		img{
			border:0;
		}
		:focus{
			outline:0;
		}
		body{
			background:#f2f2f2;
			font-family: 'Hiragino Sans GB','Microsoft Yahei',"WenQuanYi Micro Hei",SimSun,Tahoma,Arial,Helvetica,STHeiti;
			font-size:1em;
		}
		.title{
			background:#fff;
			text-align: center;
			font-size:1em;
			line-height:2.8125em;
		}
		.reg-info img{
			display: block;
			width:100%;
		}
		.form-group{
			position: relative;
			overflow: hidden;
		}
		.form-con{
			width:70.666%;
			height:1em;
			padding:.90625em 14.667%;
			background:#fff;
			border:none;
			border-bottom:1px solid #e0e0e0;
			font-size:1em;
			line-height:1em;
			color:#666;
			font-family:"微软雅黑";
		}
		.form-group i{
			position: absolute;
			left:6.4%;
			top:0;
			width:1em;
			margin:.75em 0;
			overflow: hidden;
		}
		.form-group i img{
			width:100%;
		}
		.code{
			position: absolute;
			right:4.2667%;
			top:0;
			margin:.92857em 0;
			font-size:.875em;
		}
		.code,.code button{
			background:#fff;
			border:none;
			color: #2dcc70;
			font-family:"微软雅黑";
		}
		.code button{
			font-size:1em;
			height:1.4285em;
		}
		.btn{
			width:91.467%;
			height: 2.44em;
			margin:2.22em 4.2665%;
			background:#ec6f23;
			border:none;
			border-radius:.3333em;
			font-size:1.125em;
			color:#fff;
			line-height: 2.44em;
			font-family:"微软雅黑";
		}
	</style>
</head>
<body>
<div class="title">注册</div>
<div class="reg-info">
	<img src="./resource/img/invite_register_info.jpg" alt="">
</div>
<div class="form">
	<form action="/verify_register" onsubmit="return check_all()" method="post">
		<div class="form-group">
			<i><img src="./resource/img/i_tel.png" alt=""></i>
			<input type="text" class="form-con" value="{{substr_replace($mobile,'****',3,4)}}"><span id="t_mobile"></span>
			<input type="hidden" class="form-con" value="{{$mobile}}" name="mobile" id="mobile">
			<input type="hidden" class="form-con" value="{{$invite_mobile}}" name="invite_mobile" id="invite_mobile">
		</div>
		<div class="form-group">
			<i><img src="./resource/img/i_code.png" alt=""></i>
			<input type="text" class="form-con" placeholder="请输入验证码" name="news_captcha" id="news_captcha" onblur="check_news()"><span id="t_news"></span>
			<div class="code"><button type='button' id="f_captcha">获取验证码</button></div>
		</div>
		<div class="form-group">
			<i><img src="./resource/img/i_pass.png" alt=""></i>
			<input type="password" class="form-con" placeholder="请输入密码" name="pwd" id="pwd" onblur="check_pwd()"><span id="t_pwd" ></span>
		</div>
		<div class="form-group">
			<input type="submit" value="立即注册" class="btn">
		</div>
	</form>
</div>
</body>
</html>
<script src="./resource/js/jquery-1.11.3.min.js"></script>
<script>
	//获取短信验证码
	$('#f_captcha').bind('click',function foo() {
		var mobile = document.getElementById('mobile').value;
		var wait = 60;
		var int = function fetch_captcha() {
			if (wait == 0) {
				$("#f_captcha").bind("click", foo);
				$('#f_captcha').html('获取验证码');
				clearInterval(a)
				wait = 60;
			}
			else {
				$('#f_captcha').unbind("click", foo);
				$('#f_captcha').html("重新发送(" + wait + ")");
				wait--;
			}
		}
		var a = setInterval(int, 1000);
		$.ajax({
			url: "/verify_news",
			type: "POST",
			data: "mobile=" + mobile,
			success: function (msg) {
				if (msg == 10000) {
					$("#t_news").html("<span style='color:green'>验证码发送成功,10分钟内输入有效</span>");
				}else if(msg == 160040){
					$("#t_news").html("<span style='color:red'>您当日验证码发送次数过多</span>");
					window.clearInterval(a);//停止计时器
					$(".form-code span.code").removeAttr("disabled").css('cursor','pointer');//启用按钮
					$(".form-code span.code").html("获取短信验证码");
					return false;
				}else{
					$("#t_news").html("<span style='color:red'>验证码发送错误</span>");
					window.clearInterval(a);//停止计时器
					$(".form-code span.code").removeAttr("disabled").css('cursor','pointer');//启用按钮
					$(".form-code span.code").html("获取短信验证码");
					return false;
				}
			}
		});
	})
	//短信验证
	function check_news(){
		var news_captcha = document.getElementById('news_captcha').value;
		var mobile = document.getElementById('mobile').value;
		var status = false;
		if(news_captcha){
			var ajax = new XMLHttpRequest();
			ajax.onreadystatechange = function () {
				if (ajax.readyState == 4) {
					if (ajax.responseText == 1) {
						document.getElementById("t_news").innerHTML = "<span style='color:green'>√</span>";
						status = true
					}else if(ajax.responseText == 2){
						document.getElementById("t_news").innerHTML = "<span style='color:red'>验证码已过期</span>";
					}else{
						document.getElementById("t_news").innerHTML = "<span style='color:red'>验证码错误</span>";
					}
				}
			}
			//与服务器建立连接
			ajax.open('post', '/check_news', false);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//处理请求
			ajax.send('news_captcha=' + news_captcha + '&mobile=' +mobile);
			return status
		}else{
			document.getElementById('t_news').innerHTML = "<span style='color:red'>*</span>";
			return false;
		}

	}

	//验证密码
	function check_pwd(){
		var pwd = document.getElementById('pwd').value;
		var reg=/^\w{6,16}$/
		if(reg.test(pwd)) {
			document.getElementById("t_pwd").innerHTML = "<span style='color:green'>√</span>";
			return true
		}else {
			document.getElementById('t_pwd').innerHTML = "<span style='color:red'>密码长度六位到十六位</span>"
			return false;
		}
	}

	//检测全部
	function check_all(){
		return (check_pwd()&&check_news())
	}

</script>